<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Payment
 * @copyright  Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

require_once 'Zend/Payment/RequestInterface.php';

class Zend_Payment_Request implements Zend_Payment_RequestInterface
{
    /**
     * @var string
     */
    protected $_action;

    /**
     * @var Zend_Payment_Method_Interface
     */
    protected $_method;

    /**
     * @var Zend_Payment_Data_Transaction
     */
    protected $_transaction;

    /**
     * @var array of Zend_Payment_Data_Order
     */
    protected $_order = array();

    /**
     * @var Zend_Payment_Data_Options
     */
    protected $_options;

    /**
     * @var array
     */
    protected $_advancedOptions = array();

    /**
     * Request constructor
     *
     * @param string $transaction payment transaction
     */
    public function __construct($action)
    {
        $this->setAction($action);
    }

    /**
     * Action setter
     *
     * @param string $action request action
     * @throws Zend_Payment_Exception if request type isn't string
     * @return Zend_Payment_Request
     */
    public function setAction($action)
    {
        if (!is_string($action)) {
            require_once 'Zend/Payment/Exception.php';
            throw new Zend_Payment_Exception('Request type must be as string');
        }
        $this->_action = $action;
        return $this;
    }

    /**
     * Action getter
     *
     * @return string
     */
    public function getAction()
    {
        return $this->_action;
    }

    /**
     * Payment Method getter
     * Usually Credit Card but other payment methods can be supported on gateway level
     *
     * @return Zend_Payment_Method_Card
     */
    public function getMethod()
    {
        return $this->_method;
    }

    /**
     * Payment Method setter
     *
     * @param Zend_Payment_Method_Card $method payment method
     * @return Zend_Payment_Request
     */
    public function setMethod($method)
    {
        $this->_method = $method;
        return $this;
    }

    /**
     * Options object getter
     *
     * @return Zend_Payment_Data_Options | null
     */
    public function getOptions()
    {
        return $this->_options;
    }

    /**
     * Options object setter
     *
     * @param Zend_Payment_Data_Options $options request options object
     * @return Zend_Payment_Request
     */
    public function setOptions(Zend_Payment_Data_Options $options)
    {
        $this->_options = $options;
        return $this;
    }

    /**
     * Option value getter
     *
     * @param string $code
     * @return mixed
     */
    public function getOption($code)
    {
        if ($this->_options && $this->_options->has($code)) {
            return $this->_options->get($code);
        }
        return null;
    }

    /**
     * Orders getter
     *
     * @return Zend_Payment_Data_Order | null
     */
    public function getOrder()
    {
        return $this->_order;
    }

    /**
     * Order setter
     *
     * @param Zend_Payment_Data_Order $order
     * @return Zend_Payment_Request
     */
    public function setOrder(Zend_Payment_Data_Order $order)
    {
        $this->_order = $order;
        return $this;
    }

    /**
     * Transactions getter
     *
     * @return Zend_Payment_Data_Transaction
     */
    public function getTransaction()
    {
        return $this->_transaction;
    }

    /**
     * Transaction setter
     *
     * @param Zend_Payment_Data_Transaction $transaction
     * @return Zend_Payment_Request
     */
    public function setTransaction(Zend_Payment_Data_Transaction $transaction)
    {
        $this->_transaction = $transaction;
        return $this;
    }

    /**
     * Advanced options getter
     *
     * @return array
     */
    public function getAdvancedOptions()
    {
        return $this->_advancedOptions;
    }

    /**
     * Advanced options setter
     *
     * @param array $options
     * @return Zend_Payment_Request
     */
    public function setAdvancedOptions(array $options)
    {
        $this->_advancedOptions = $options;
        return $this;
    }
}
